<?php

session_start(); 

$GLOBALS['config'] = array(

	'mysql' =>  array (
		'host' => 'localhost',
		'username' => 'root',
		'password' => '',
		'db' => 'cookingclubapp'

		),
	
	'remember' =>  array (
		'cookie_name' => 'hash',
		'cookie_expiry' => 604800
		),
	
	'session' =>  array (
		'session_name' => 'user',
		'token_name' => 'token'
		)

);

spl_autoload_register(function($class){
	require_once 'lib/'.$class.'.php';
});



require_once 'functions/sanitize.php';

if (Cookie::exists(Config::get('remember/cookie_name')) && !Session::exists(Config::get('session/session_name'))) {
	//echo "user has to be remembered";
	$hash = Cookie::get(Config::get('remember/cookie_name'));

	$hashCheck = DB::getInstance()->get('user_session', array('hash', '=', $hash));
	//echo "Mus be remembered";
	if ($hashCheck->count()) {
		echo $hashCheck->first()->user_id;
		$user = new User($hashCheck->first()->user_id);
		$user->login();
	}

}


DEFINE("URL", $_SERVER["REQUEST_URI"]);
